package com.base.component.app.apple;

import com.gitee.magic.framework.base.rest.HttpRequest;
import com.gitee.magic.framework.base.rest.HttpWrapper;
import com.gitee.magic.framework.base.rest.RequestMethodEnum;

public class AppleApi {

	public static String authKeys() {
		HttpRequest request = new HttpRequest("https://appleid.apple.com/auth/keys", RequestMethodEnum.GET);
		HttpWrapper wrapper = new HttpWrapper();
		return wrapper.start(request);
	}

	public static String authToken(String clientId, String clientSecret, String authorizationCode) {
		HttpRequest request = new HttpRequest("https://appleid.apple.com/auth/token");
		request.setHeader(HttpWrapper.CONTENTTYPE, HttpWrapper.CONTENTTYPE_URLENCODE);
		request.setUrlParam("client_id", clientId);
		request.setUrlParam("client_secret", clientSecret);
		request.setUrlParam("code", authorizationCode);
		request.setUrlParam("grant_type", "authorization_code");
		HttpWrapper wrapper = new HttpWrapper();
		String content = wrapper.start(request);
		System.out.println(content);
		return content;
	}

	public static String authRevoke(String clientId, String clientSecret, String refreshToken) {
		HttpRequest request = new HttpRequest("https://appleid.apple.com/auth/revoke");
		request.setHeader(HttpWrapper.CONTENTTYPE, HttpWrapper.CONTENTTYPE_URLENCODE);
		request.setUrlParam("client_id", clientId);
		request.setUrlParam("client_secret", clientSecret);
		request.setUrlParam("grant_type", "refresh_token");
		request.setUrlParam("token", refreshToken);
		HttpWrapper wrapper = new HttpWrapper();
		String content = wrapper.start(request);
		System.out.println(content);
		return content;
	}

}
